home *** CD-ROM | disk | FTP | other *** search
- Path: news.NetVision.net.il!news
- From: Ivan Krivyakov <ivan@cmt.co.il>
- Newsgroups: comp.lang.c++
- Subject: Re: How to prototype a class?
- Date: 19 Feb 1996 12:53:15 GMT
- Organization: CMT Medical Technologies, ltd.
- Message-ID: <4g9rrr$78s@news.NetVision.net.il>
- References: <4fvjhe$c6o@nuntius.u-net.net> <DMtxzu.8HK@tr.unisys.com>
- NNTP-Posting-Host: cmt13.cmt.co.il
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 1.22 (Windows; I; 32bit)
-
- "Benjamin M. Romer" <bmr1@trpo4.tr.unisys.com> wrote:
-
- > Use a forward declaration:
- >
- > class A; //I promise to define A later.
- >
- > class B
- > {
- > ...
- > private:
- > A dataMember; // <--- here is an error!
- > };
- >
- > Class A
- > {
- > ...
- > private:
- > B dataMember;
- > };
- >
- > Hope this helps.
- >
- > Benjamin M. Romer
-
- Sorry, but this won't work!
-
- In the point where you declare B::dataMember, class A is not still defined
- although compiler knowns that it exists.
-
- To process a declaration of B::dataMember compiler should know, for example,
- what is the size of objects of type A. This is obviously not known for one-pass compiler
- in the point where B::dataMember is declared.
-
- You may use pointer to A instead of A as follows:
-
- class A;
-
- class B
- {
- ...
- A* dataMember; //<--- legal
- ...
- };
-
- > #include <stddisclaim.h>
-
- Good idea! :)
-
- Best regards,
- Ivan (ivan@cmt.co.il)
-
-
-